package chapter11;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author : DuJiabao
 * @Date : 2021/2/19 23:09
 * @Project : thinking-in-java
 * @File : null.java
 * @Desc :
 */
public class IterableImpl implements Iterable<String> {
  String[] s = "faf gdagfa aff gag".split(" ");

  @Override
  public Iterator<String> iterator() {
    return new Iterator<String>() {
      private int index = 0;

      @Override
      public boolean hasNext() {
        return index < s.length;
      }

      @Override
      public String next() {
        return s[index++];
      }
    };
  }

  @Test
  public void test() {
    IterableImpl strings = new IterableImpl();
    for (String string : strings) {
      System.out.println(string);
    }
  }
}













